package fx.iog.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;

public class DateDialog extends DialogFragment implements OnDateSetListener {

	private View view_attr;
	private Calendar calendar = Calendar.getInstance();

	public DateDialog(View view) {
		this.view_attr = view;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return new DatePickerDialog(getActivity(), this, 1990, 6, 1);
	}

	@Override
	public void onDateSet(DatePicker view, int year, int monthOfYear,
			int dayOfMonth) {


		if (view_attr instanceof EditText) {
			
			calendar.set(year, monthOfYear, dayOfMonth);
			
			SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
			((EditText) view_attr).setText(sdf.format(calendar.getTime()));

		}

	}

}
